// pages/Income_details/index.js
import {
  HTTP
} from '../../../utils/http.js'
let Myhttp = new HTTP()
import Dates from '../../../date.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dates:'',
    total_money:'',
    lists:'',
    start: {
      startA: '',
      startB: ''
    },
    date_start: '',
    date_end: ''
  },
  post: function (that) {
    Myhttp.request({
      url: 'questionnaire/questionnaire/incomeList',
      method: 'POST',
      data: {
        page: this.data.page,
        date_start: this.data.date_start,
        end_time: this.data.date_end
      },
      success: (res) => {
        //console.log(res)
        let list = res.data.data.list
        list.forEach(val => {
          let date = Dates.formatTime(val.create_time * 1000, 'YY-M-D');
          val.create_time = date
          // val.price
          val.index = 1
        })
        // console.log(list)
        that.setData({
          total_money: res.data.data.total_money,
          lists: list
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let date = new Date();
    let year = (date.getFullYear()).toString(); //获取完整的年份(4位)
    let Month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
    let today = date.getDate(); //获取当前日(1-31)
    //console.log(Month)
    Month < 10 ? '0' + Month : Month
    today < 10 ? '0' + today : today
    let dates = year + '-' + Month + '-' + today
    //console.log(dates)
    let start_time = (year - 2) + '-' + Month + '-' + today
    //let end_time = (year + 2) + '-' + Month + '-' + today
    let aa = {
      startA: start_time,
      startB: start_time
    }
    this.setData({
      dates: dates,
      start: aa,
    })
    
    //console.log(end_time)
    let that = this
    this.post(that)
  },
  dateStart: function (e) {
    this.setData({
      date_start: e.detail.date.value,
      'start.startB': e.detail.date.value
    })
    let that = this
    this.post(that)
   },
  dateEnd: function (e) {
    this.setData({
      date_end: e.detail.date.value
    })
    //console.log(e)
    let that = this
    this.post(that)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      path: '/pages/personal/Income_details/index'
    }
  }
})